package com.letoo.dragon.core.service.impl;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.github.miemiedev.mybatis.paginator.domain.PageBounds;
import com.github.miemiedev.mybatis.paginator.domain.PageList;
import com.letoo.dragon.core.service.BaseService;
import com.letoo.dragon.dataaccess.dao.db.BaseDBDAO;
import com.letoo.dragon.dataaccess.domain.BaseDomain;

public abstract class BaseServiceImpl<T extends BaseDomain> implements BaseService<T> {
  /**
   * 日志
   */
  protected final Logger LOG = LoggerFactory.getLogger(getClass());

  protected abstract BaseDBDAO<T> getDAO();

  public T findById(long id) {
    return getDAO().findById(id);
  }

  public void update(T t) {
    getDAO().update(t);
  }

  @Override
  public Long save(T entity) {
    getDAO().save(entity);
    return entity.getId();
  }

  @Override
  public void delete(String ids) {
    String[] strs = ids.split(",");
    for (String str : strs) {
      getDAO().delete(new Long(str));
    }
  }

  @Override
  public PageList<T> findByPage(PageBounds pageBounds) {
    return getDAO().findByPage(pageBounds);
  }

  @Override
  public Integer getTotalCount() {
    return getDAO().getTotalCount();
  }
}
